<?php
// +----------------------------------------------------------------------
// | CoreThink [ Simple Efficient Excellent ]
// +----------------------------------------------------------------------
// | Copyright (c) 2014 http://www.corethink.cn All rights reserved.
// +----------------------------------------------------------------------
// | Author: jry <598821125@qq.com> <http://www.corethink.cn>
// +----------------------------------------------------------------------
namespace Manual\Controller\Home;
use Home\Controller\HomeController;
/**
 * 默认控制器
 * @author jry <598821125@qq.com>
 */
class IndexController extends HomeController{
    /**
     * 默认方法
     * @author jry <598821125@qq.com>
     */
    public function index(){
        $con['status'] = 1;
        $app_list = D('Manual')->page(!empty($_GET["p"])?$_GET["p"]:1,28)->where($con)->select();
        foreach($app_list as &$app){
            $app['user'] = get_user_info($app['uid']); //获取该模块作者信息
        }
        $page = new \Common\Util\Page(D('Manual')->where($con)->count(), 28);
        $this->assign('app_list', $app_list);
        $this->assign('meta_title', "手册列表");
        Cookie('__forward__', $_SERVER['REQUEST_URI']);
        $this->display();
    }

    /**
     * 手册在线阅读
     * @author jry <598821125@qq.com>
     */
    public function read($title, $keyword = ''){
        $title = iconv("gb2312","utf-8//IGNORE",$title);
        $con['title'] = $title;
        $manual_info = D('Manual')->where($con)->find();
        
        $con = array();
        $con['status'] = 1;
        $con['mid'] = $manual_info['id'];
        $con['content'] = array('like', '%'.$keyword.'%');
        $manual_page_list = D('ManualPage')->field('id,pid,title,status')->where($con)->order("sort asc")->select();
        
        $this->assign('manual_info', $manual_info);
        $this->assign('manual_page_list', json_encode($manual_page_list));
        $this->assign('meta_title', $manual_info['title']);
        Cookie('__forward__', $_SERVER['REQUEST_URI']);
        $this->display();
    }

    /**
     * 手册在线阅读
     * @author jry <598821125@qq.com>
     */
    public function getContent($id){
        $map['status'] = array('eq', 1); //正常
        $info = D('ManualPage')->where($map)->find($id);
        if($info){
            $info['name']=M("Employee")->where("uid=$info[uid]")->getField('name');
            $data['status']  = 1;
            $data['info']  = '获取数据成功';
            $data['data']  = json_encode($info);
        }else{
            $data['status']  = 0;
            $data['info']  = '获取数据失败';
        }
        $this->ajaxReturn($data);
    }
}